/**
 * Person.java is created by Zachariah at 2012-2-14 下午02:45:57
 */
package com.zack.designPattern.memento;

/**
 * @author zachariah zzcfrog@gmail.com
 *
 */
public class Person {

	private String name;
	
	private int age;
	
	public Person(String name, int age){
		this.name = name;
		this.age = age;
	}
	
	public void older(){
		this.age++;
	}

	public void restoreFromMemento(Memento m){
		PersonMemento pm = (PersonMemento)m;
		this.age =pm.age;
		this.name = pm.name;
	}
	
	public PersonMemento createMemento(){
		return new PersonMemento(name, age);
	}
	
	public String toString(){
		return this.name+"-"+this.age;
	}
	
	private class PersonMemento implements Memento{
		
		private String name;
		
		private int age;
		
		private PersonMemento(String name , int age){
			this.name = name;
			this.age = age;
		}
	}
	
}
